

use async_trait::async_trait;
use serde_json::Value;
use shq_common::prelude::{report::{DisplayCols, ReportDataResponse, ReportDefine}, OrderItems,WhereCauses};

use super::ListReport;
use crate::error::Result;
pub struct ChartReport<'a> {
    list_rept: ListReport<'a>,
}
impl<'a> ChartReport<'a> {
    pub async fn from(
        rept_name: &'a str,
        params: Vec<(&'a str, String)>,
        user_id: u32,
        menu_id: u32,
    ) -> Result<Self> {
        let rept = ChartReport {
            list_rept: ListReport::from(rept_name, params, user_id,menu_id).await?,
        };
        Ok(rept)
    }
}
#[async_trait]
impl<'a> super::ReportTrait for ChartReport<'a> {
    async fn get_rept_define(&self) -> Result<ReportDefine> {
        self.list_rept.get_rept_define().await
    }
    async fn get_options_map(&self) -> Result<std::collections::HashMap<String, Vec<String>>> {
        self.list_rept.get_options_map().await
    }
    async fn get_data_list(
        &self,
        where_causes: Option<WhereCauses>,
        orders: Option<OrderItems>,
        display_cols: DisplayCols,
        group_index: u8,
        drill_down_requ: Vec<(u8, Value)>,
        extra_where: Option<String>,
        page: u32,
        size: u16,
    ) -> Result<ReportDataResponse> {
        let ldatas = self.list_rept
            .get_data_list(
                where_causes,
                orders,
                display_cols,
                group_index,
                drill_down_requ,
                extra_where,
                page,
                size,
            )
            .await?;
        Ok(ldatas)
    }
    async fn export_xslx(
        &self,
        where_causes: Option<WhereCauses>,
        orders: Option<OrderItems>,
        display_cols: DisplayCols,
        group_index: u8,
        drill_downs: Vec<(u8, Value)>,
        extra_where: Option<String>,
        one_sheet_on_file: bool,
    ) -> Result<Vec<u8>> {
        self.list_rept
            .export_xslx(
                where_causes,
                orders,
                display_cols,
                group_index,
                drill_downs,
                extra_where,
                one_sheet_on_file
            )
            .await
    }
}